package com.sc.nft.dao;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import lombok.extern.slf4j.Slf4j;
import com.sc.nft.entity.UserEcologyNotSettleList;
import com.sc.nft.mapper.UserEcologyNotSettleListMapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Repository;

/**
 * 生态-不发周期奖励表(sc_user_ecology_not_settle_list)数据DAO
 *
 * @author Sun
 * @since 2024-05-30 11:45:29
 * @description 由 Mybatisplus Code Generator 创建
 */
@Slf4j
@Repository
public class UserEcologyNotSettleListDao extends ServiceImpl<UserEcologyNotSettleListMapper, UserEcologyNotSettleList> {

    public UserEcologyNotSettleList getLastOneByUserIdAndEquityPropsId(Long userId, Long equityPropsId) {
        LambdaQueryWrapper<UserEcologyNotSettleList> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(UserEcologyNotSettleList::getUserId, userId);
        wrapper.eq(UserEcologyNotSettleList::getEquityPropsId, equityPropsId);
        wrapper.orderByDesc(UserEcologyNotSettleList::getId);
        wrapper.last("limit 1");
        return getOne(wrapper);
    }

    public Boolean addAlreadyCountById(Long id, Integer count) {
        LambdaUpdateWrapper<UserEcologyNotSettleList> wrapper = new LambdaUpdateWrapper<>();
        wrapper.eq(UserEcologyNotSettleList::getId, id);
        wrapper.setSql("already_count = already_count + " + count);
        return update(new UserEcologyNotSettleList(), wrapper);
    }

    public Boolean deleteById(Long id) {
        LambdaUpdateWrapper<UserEcologyNotSettleList> wrapper = new LambdaUpdateWrapper<>();
        wrapper.eq(UserEcologyNotSettleList::getId, id);
        return remove(wrapper);
    }
}